/***************************************************************************
 *   Copyright (C) 2008 by Justin L. Boss                                  *
 *   justin@rtechguys.com                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <kconfiggroup.h>
#include <kglobal.h>
#include <ksharedconfig.h>
#include <QtDebug>
#include "koceansetting.h"

Settings::Settings()
{
    load();
}

void Settings::load()
{
    KConfigGroup config( KGlobal::config(), "Settings" );

    WaveEnabled = config.readEntry("WaveEnabled",true);
    WaveWidth = config.readEntry("WaveWidth",120);
    WaveDepth = config.readEntry("WaveDepth",70);
    WaveSpeed = config.readEntry("WaveSpeed", 900);
    WaveSize = config.readEntry("WaveSize", 40);

    SampleBuffer = config.readEntry("SampleBuffer",true);
    Ambient = config.readEntry("Ambient", 20);
    CausticsFloor = config.readEntry("CausticsFloor",40);
    CausticsWave = config.readEntry("CausticsWave",34);
    Clarity = config.readEntry("Clarity",40);
    Light = config.readEntry("Light",70);
    Color = config.readEntry("Color", QColor(46,130,179));

    Orca_Count = config.readEntry("Orca_Count", 2);
    Orca_Small = config.readEntry("Orca_Small", 9);
    Orca_Larg = config.readEntry("Orca_Larg", 20);
    Orca_Speed = config.readEntry("Orca_Speed", 50);
    Orca_Pattern = config.readEntry("Orca_Pattern", 1);
    Orca_Agility = config.readEntry("Orca_Agility", 50);
    Orca_Far = config.readEntry("Orca_Far", 30);
    Orca_Near = config.readEntry("Orca_Near", 29);
    Orca_Depth = config.readEntry("Orca_Depth", 1);
    Orca_TSpeed = config.readEntry("Orca_TSpeed", 0);
    Orca_TMove = config.readEntry("Orca_TMove", 12);

    LS_Count = config.readEntry("LS_Count",2);
    LS_Small = config.readEntry("LS_Small",9);
    LS_Larg = config.readEntry("LS_Larg",15);
    LS_Speed = config.readEntry("LS_Speed",20);
    LS_Pattern = config.readEntry("LS_Pattern",1);
    LS_Agility = config.readEntry("LS_Agility",50);
    LS_Far = config.readEntry("LS_Far",20);
    LS_Near = config.readEntry("LS_Near",3);
    LS_Depth = config.readEntry("LS_Depth",1);
    LS_TSpeed = config.readEntry("LS_TSpeed", 0);
    LS_TMove = config.readEntry("LS_TMove", 12);

    GW_Count = config.readEntry("GW_Count", 1);
    GW_Small = config.readEntry("GW_Small", 15);
    GW_Larg = config.readEntry("GW_Larg", 18);
    GW_Speed = config.readEntry("GW_Speed", 15);
    GW_Pattern = config.readEntry("GW_Pattern", 1);
    GW_Agility = config.readEntry("GW_Agility", 30);
    GW_Far = config.readEntry("GW_Far", 20);
    GW_Near = config.readEntry("GW_Near", 10);
    GW_Depth = config.readEntry("GW_Depth", -3);
    GW_TSpeed = config.readEntry("GW_TSpeed", 20);
    GW_TMove = config.readEntry("GW_TMove", 10);

    BC_Count = config.readEntry("BC_Count", 5);
    BC_Small = config.readEntry("BC_Small", 6);
    BC_Larg = config.readEntry("BC_Larg", 9);
    BC_Speed = config.readEntry("BC_Speed", 11);
    BC_Pattern = config.readEntry("BC_Pattern", 2);
    BC_Agility = config.readEntry("BC_Agility", 10);
    BC_Far = config.readEntry("BC_Far", 6);
    BC_Near = config.readEntry("BC_Near", 5);
    BC_Depth = config.readEntry("BC_Depth", 4);
    BC_TSpeed = config.readEntry("BC_TSpeed", 20);
    BC_TMove = config.readEntry("BC_TMove", 10);

    Sail_Count = config.readEntry("Sail_Count", 1);
    Sail_Small = config.readEntry("Sail_Small", 6);
    Sail_Larg = config.readEntry("Sail_Larg", 8);
    Sail_Speed = config.readEntry("Sail_Speed", 89);
    Sail_Pattern = config.readEntry("Sail_Pattern", 2);
    Sail_Agility = config.readEntry("Sail_Agility", 32);
    Sail_Far = config.readEntry("Sail_Far", 80);
    Sail_Near = config.readEntry("Sail_Near", 50);
    Sail_Depth = config.readEntry("Sail_Depth", 0);
    Sail_TSpeed = config.readEntry("Sail_TSpeed", 20);
    Sail_TMove = config.readEntry("Sail_TMove", 10);

    Spade_Count = config.readEntry("Spade_Count", 50);
    Spade_Small = config.readEntry("Spade_Small", 1);
    Spade_Larg = config.readEntry("Spade_Larg", 3);
    Spade_Speed = config.readEntry("Spade_Speed", 14);
    Spade_Pattern = config.readEntry("Spade_Pattern", 0);
    Spade_Agility = config.readEntry("Spade_Agility", 65);
    Spade_Far = config.readEntry("Spade_Far", 5);
    Spade_Near = config.readEntry("Spade_Near", 4);
    Spade_Depth = config.readEntry("Spade_Depth", 2);
    Spade_TSpeed = config.readEntry("Spade_TSpeed", 20);
    Spade_TMove = config.readEntry("Spade_TMove", 10);

    Tripletail_Count = config.readEntry("Tripletail_Count", 2);
    Tripletail_Small = config.readEntry("Tripletail_Small", 7);
    Tripletail_Larg = config.readEntry("Tripletail_Larg", 10);
    Tripletail_Speed = config.readEntry("Tripletail_Speed", 11);
    Tripletail_Pattern = config.readEntry("Tripletail_Pattern", 2);
    Tripletail_Agility = config.readEntry("Tripletail_Agility", 65);
    Tripletail_Far = config.readEntry("Tripletail_Far", 30);
    Tripletail_Near = config.readEntry("Tripletail_Near", 5);
    Tripletail_Depth = config.readEntry("Tripletail_Depth", 2);
    Tripletail_TSpeed = config.readEntry("Tripletail_TSpeed", 20);
    Tripletail_TMove = config.readEntry("Tripletail_TMove", 15);

    ShipEnabled = config.readEntry("ShipEnabled", true);
    MausoleumEnabled = config.readEntry("MausoleumEnabled", true);
    RockEnabled = config.readEntry("RockEnabled", true);
    SeaFloorEnabled = config.readEntry("SeaFloorEnabled", true);

    RockingEnabled = config.readEntry("RockingEnabled", true);
    Amplitude = config.readEntry("Amplitude", 0.1);
    Frequency = config.readEntry("Frequency", 0.1);
}

void Settings::defaults()
{
    WaveEnabled = true;
    WaveWidth = 120;
    WaveDepth = 70;
    WaveSpeed = 900;
    WaveSize = 40;

    SampleBuffer = true;
    Ambient = 20;
    CausticsFloor = 40;
    CausticsWave = 34;
    Clarity = 40;
    Light = 70;
    Color = QColor(46,130,179);

    Orca_Count = 2;
    Orca_Small = 9;
    Orca_Larg = 20;
    Orca_Speed = 50;
    Orca_Pattern = 1;
    Orca_Agility = 50;
    Orca_Far = 30;
    Orca_Near = 29;
    Orca_Depth = 1;
    Orca_TSpeed = 0;
    Orca_TMove = 12;

    LS_Count = 2;
    LS_Small = 9;
    LS_Larg = 15;
    LS_Speed = 20;
    LS_Pattern = 1;
    LS_Agility = 50;
    LS_Far = 20;
    LS_Near = 3;
    LS_Depth = 1;
    LS_TSpeed = 0;
    LS_TMove = 12;

    GW_Count = 1;
    GW_Small = 15;
    GW_Larg = 18;
    GW_Speed = 15;
    GW_Pattern = 1;
    GW_Agility = 30;
    GW_Far = 20;
    GW_Near = 10;
    GW_Depth = -3;
    GW_TSpeed = 20;
    GW_TMove = 10;

    BC_Count = 5;
    BC_Small = 6;
    BC_Larg = 9;
    BC_Speed = 11;
    BC_Pattern = 2;
    BC_Agility = 10;
    BC_Far = 6;
    BC_Near = 5;
    BC_Depth = 4;
    BC_TSpeed = 20;
    BC_TMove = 10;

    Sail_Count = 1;
    Sail_Small = 6;
    Sail_Larg = 8;
    Sail_Speed = 89;
    Sail_Pattern = 2;
    Sail_Agility = 32;
    Sail_Far = 80;
    Sail_Near = 50;
    Sail_Depth = 0;
    Sail_TSpeed = 20;
    Sail_TMove = 10;

    Spade_Count = 50;
    Spade_Small = 1;
    Spade_Larg = 3;
    Spade_Speed = 14;
    Spade_Pattern = 0;
    Spade_Agility = 65;
    Spade_Far = 4;
    Spade_Near = 5;
    Spade_Depth = 5;
    Spade_TSpeed = 20;
    Spade_TMove = 10;

    Tripletail_Count = 2;
    Tripletail_Small = 7;
    Tripletail_Larg = 10;
    Tripletail_Speed = 11;
    Tripletail_Pattern = 2;
    Tripletail_Agility = 65;
    Tripletail_Far = 30;
    Tripletail_Near = 5;
    Tripletail_Depth = 2;
    Tripletail_TSpeed = 20;
    Tripletail_TMove = 15;

    ShipEnabled = true;
    MausoleumEnabled = true;
    RockEnabled = true;
    SeaFloorEnabled = true;

    RockingEnabled = true;
    Amplitude =  0.1;
    Frequency =  0.1;
}

void Settings::save()
{
    KConfigGroup config( KGlobal::config(), "Settings" );

    config.writeEntry("WaveEnabled", WaveEnabled);
    config.writeEntry("WaveWidth", WaveWidth);
    config.writeEntry("WaveDepth", WaveDepth);
    config.writeEntry("WaveSpeed", WaveSpeed);
    config.writeEntry("WaveSize", WaveSize);

    config.writeEntry("SampleBuffer", SampleBuffer);
    config.writeEntry("Ambient", Ambient);
    config.writeEntry("CausticsFloor", CausticsFloor);
    config.writeEntry("CausticsWave", CausticsWave);
    config.writeEntry("Clarity", Clarity);
    config.writeEntry("Light", Light);
    config.writeEntry("Color", Color);

    config.writeEntry("Orca_Count", Orca_Count);
    config.writeEntry("Orca_Small", Orca_Small);
    config.writeEntry("Orca_Larg", Orca_Larg);
    config.writeEntry("Orca_Speed", Orca_Speed);
    config.writeEntry("Orca_Pattern", Orca_Pattern);
    config.writeEntry("Orca_Agility", Orca_Agility);
    config.writeEntry("Orca_Far", Orca_Far);
    config.writeEntry("Orca_Near", Orca_Near);
    config.writeEntry("Orca_Depth", Orca_Depth);
    config.writeEntry("Orca_TSpeed", Orca_TSpeed);
    config.writeEntry("Orca_TMove", Orca_TMove);

    config.writeEntry("LS_Count", LS_Count);
    config.writeEntry("LS_Small", LS_Small);
    config.writeEntry("LS_Larg", LS_Larg);
    config.writeEntry("LS_Speed", LS_Speed);
    config.writeEntry("LS_Pattern", LS_Pattern);
    config.writeEntry("LS_Agility", LS_Agility);
    config.writeEntry("LS_Far", LS_Far);
    config.writeEntry("LS_Near", LS_Near);
    config.writeEntry("LS_Depth", LS_Depth);
    config.writeEntry("LS_TSpeed", LS_TSpeed);
    config.writeEntry("LS_TMove", LS_TMove);

    config.writeEntry("GW_Count", GW_Count);
    config.writeEntry("GW_Small", GW_Small);
    config.writeEntry("GW_Larg", GW_Larg);
    config.writeEntry("GW_Speed", GW_Speed);
    config.writeEntry("GW_Pattern", GW_Pattern);
    config.writeEntry("GW_Agility", GW_Agility);
    config.writeEntry("GW_Far", GW_Far);
    config.writeEntry("GW_Near", GW_Near);
    config.writeEntry("GW_Depth", GW_Depth);
    config.writeEntry("GW_TSpeed", GW_TSpeed);
    config.writeEntry("GW_TMove", GW_TMove);

    config.writeEntry("BC_Count", BC_Count);
    config.writeEntry("BC_Small", BC_Small);
    config.writeEntry("BC_Larg", BC_Larg);
    config.writeEntry("BC_Speed", BC_Speed);
    config.writeEntry("BC_Pattern", BC_Pattern);
    config.writeEntry("BC_Agility", BC_Agility);
    config.writeEntry("BC_Far", BC_Far);
    config.writeEntry("BC_Near", BC_Near);
    config.writeEntry("BC_Depth", BC_Depth);
    config.writeEntry("BC_TSpeed", BC_TSpeed);
    config.writeEntry("BC_TMove", BC_TMove);

    config.writeEntry("Sail_Count", Sail_Count);
    config.writeEntry("Sail_Small", Sail_Small);
    config.writeEntry("Sail_Larg", Sail_Larg);
    config.writeEntry("Sail_Speed", Sail_Speed);
    config.writeEntry("Sail_Pattern", Sail_Pattern);
    config.writeEntry("Sail_Agility", Sail_Agility);
    config.writeEntry("Sail_Far", Sail_Far);
    config.writeEntry("Sail_Near", Sail_Near);
    config.writeEntry("Sail_Depth", Sail_Depth);
    config.writeEntry("Sail_TSpeed", Sail_TSpeed);
    config.writeEntry("Sail_TMove", Sail_TMove);

    config.writeEntry("Spade_Count", Spade_Count);
    config.writeEntry("Spade_Small", Spade_Small);
    config.writeEntry("Spade_Larg", Spade_Larg);
    config.writeEntry("Spade_Speed", Spade_Speed);
    config.writeEntry("Spade_Pattern", Spade_Pattern);
    config.writeEntry("Spade_Agility", Spade_Agility);
    config.writeEntry("Spade_Far", Spade_Far);
    config.writeEntry("Spade_Near", Spade_Near);
    config.writeEntry("Spade_Depth", Spade_Depth);
    config.writeEntry("Spade_TSpeed", Spade_TSpeed);
    config.writeEntry("Spade_TMove", Spade_TMove);

    config.writeEntry("Tripletail_Count", Tripletail_Count);
    config.writeEntry("Tripletail_Small", Tripletail_Small);
    config.writeEntry("Tripletail_Larg", Tripletail_Larg);
    config.writeEntry("Tripletail_Speed", Tripletail_Speed);
    config.writeEntry("Tripletail_Pattern", Tripletail_Pattern);
    config.writeEntry("Tripletail_Agility", Tripletail_Agility);
    config.writeEntry("Tripletail_Far", Tripletail_Far);
    config.writeEntry("Tripletail_Near", Tripletail_Near);
    config.writeEntry("Tripletail_Depth", Tripletail_Depth);
    config.writeEntry("Tripletail_TSpeed", Tripletail_TSpeed);
    config.writeEntry("Tripletail_TMove", Tripletail_TMove);

    config.writeEntry("ShipEnabled", ShipEnabled);
    config.writeEntry("MausoleumEnabled", MausoleumEnabled);
    config.writeEntry("RockEnabled", RockEnabled);
    config.writeEntry("SeaFloorEnabled", SeaFloorEnabled);

    config.writeEntry("RockingEnabled",  RockingEnabled);
    config.writeEntry("Amplitude",	Amplitude);
    config.writeEntry("Frequency",  Frequency);

    config.sync();
}
